/**
 * Filename: LocalManageAdapter.java
 *
 * @author Firefly
 * @contact postfirefly@163.com
 * @time 2016/3/17 15:22
 */
package com.github.postsanf.yinian.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.activity.LocalManageVideoPreviewActivity;
import com.github.postsanf.yinian.bean.YNVideoInfo;
import com.github.postsanf.yinian.constants.SelectedImg;
import com.github.postsanf.yinian.utils.DisplayUtils;
import com.github.postsanf.yinian.utils.LocalViewHolder;
import com.github.postsanf.yinian.utils.UIHelper;

import java.util.ArrayList;

public class LocalManageVideoSelAdapter extends CommonAdapter2<YNVideoInfo> {
    private Context mContext;

    public LocalManageVideoSelAdapter(Context context, int itemLayoutId) {
        super(context, SelectedImg.mSelectedVideo, itemLayoutId, 0);
        this.mContext = context;
    }

    @Override
    public void convert(final LocalViewHolder helper, final YNVideoInfo ynVideoInfo, final int position, final Boolean isFirst) {
        final ImageView mImageView = helper.getView(R.id.iv_album_grid_item_image);
        final ImageView mSelect = helper.getView(R.id.id_item_select);
        mImageView.setImageBitmap(ynVideoInfo.getThumb());
        final String item = ynVideoInfo.getPath();
        int itemWidth = (UIHelper.getScreenWidth(mContext) - 3 * DisplayUtils.dp2px(mContext, 1)) / 4;
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(itemWidth, itemWidth);
        mImageView.setLayoutParams(params);
        mSelect.setOnClickListener(new View.OnClickListener() {
            //选择，则将图片变暗，反之则反之
            @Override
            public void onClick(View v) {
                if (SelectedImg.mSelectedImage.contains(item)) {
                    SelectedImg.mSelectedImage.remove(item);
                }
                SelectedImg.mSelectedVideo.clear();
                notifyDataSetChanged();
                mContext.sendBroadcast(new Intent("updatebuttomgridview"));
            }
        });
        mImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ArrayList<String> zoomlist = new ArrayList<>();
                zoomlist.clear();
                zoomlist.addAll(SelectedImg.mSelectedImage);
                if (zoomlist.size() == 0)
                    return;
                Intent zoomintent = new Intent(mContext, LocalManageVideoPreviewActivity.class);
                zoomintent.putExtra("localVideopath", item);
                mContext.startActivity(zoomintent);
            }
        });
    }

}